package com.whjz.dcfs.jzxx.struts.action;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;

import com.whjz.dcfs.jzxx.dao.IDcfsMgdJbxxDAO;
import com.whjz.dcfs.jzxx.model.DcfsMgdJbxx;
import com.whjz.dcfs.util.BaseAction;

public class JZSBMGDAction extends BaseAction{

	private static final long serialVersionUID = 1L;
	
	private DcfsMgdJbxx dcfsMgdJbxx;
	@Autowired
	public IDcfsMgdJbxxDAO dcfsMgdJbxxDAO;

	public DcfsMgdJbxx getDcfsMgdJbxx() {
		return dcfsMgdJbxx;
	}

	public void setDcfsMgdJbxx(DcfsMgdJbxx dcfsMgdJbxx) {
		this.dcfsMgdJbxx = dcfsMgdJbxx;
	}
	
	public void insertDcfsMgdJbxxByCond() throws Exception{
		try{
			//getHttpServletResponse().setCharacterEncoding("utf-8");
			dcfsMgdJbxxDAO.insertDcfsMgdJbxxByCond(dcfsMgdJbxx);
			getHttpServletResponse().getWriter().println("{success:'true',msg:'添加成功'}");	
		}catch(Exception e){
			e.printStackTrace();
		}
	}
	
	public void deleteDcfsMgdJbxxByCond() throws Exception{
		try{
			dcfsMgdJbxxDAO.deleteDcfsMgdJbxxByCond(dcfsMgdJbxx);
			getHttpServletResponse().getWriter().println("{success:'true',msg:'删除成功'}");
		}catch(Exception e){
			e.printStackTrace();
		}
	}
	
	public void getDcfsMgdJbxxByCond_sb() throws Exception{
		try{
			List<DcfsMgdJbxx> list=dcfsMgdJbxxDAO.getDcfsMgdJbxxByCond_sb(dcfsMgdJbxx);
			String fsybh="";
			if(list!=null&&list.size()>0){
				for(int i=0;i<list.size();i++){
					fsybh+=list.get(i).getMgdfsybh();
					if(i<list.size()-1){
						fsybh+=",";
					}
				}
			}
			getHttpServletResponse().getWriter().println(fsybh);
		}catch(Exception e){
			e.printStackTrace();
		}
	}
	
	public void getDcfsMgdJbxxByCond() throws Exception{
		getHttpServletRequest().setCharacterEncoding("utf-8");
		getHttpServletResponse().setCharacterEncoding("utf-8");
		List<DcfsMgdJbxx> list=dcfsMgdJbxxDAO.getDcfsMgdJbxxListByCond(dcfsMgdJbxx);
		StringBuffer sb=new StringBuffer();
		sb.append("{MGD:[");
		if(list!=null&&list.size()>0){
			for(int i=0;i<list.size();i++){
				sb.append("{");
				sb.append("MGD_BH:'"+(list.get(i).getMgdbh()==null?"":list.get(i).getMgdbh())+"',");
				sb.append("MGD_FSY_BH:'"+(list.get(i).getMgdfsybh()==null?"":list.get(i).getMgdfsybh())+"',");
				sb.append("MGD_MC:'"+(list.get(i).getMgdmc()==null?"":list.get(i).getMgdmc())+"',");
				sb.append("MGD_DZ:'"+(list.get(i).getMgddz()==null?"":list.get(i).getMgddz())+"',");
				sb.append("MGD_FW:'"+(list.get(i).getMgdfw()==null?"":list.get(i).getMgdfw())+"',");
				sb.append("MGD_CZJL:'"+(list.get(i).getMgdczjl()==null?"":list.get(i).getMgdczjl())+"',");
				sb.append("MGD_LXFS:'"+(list.get(i).getMgdlxfs()==null?"":list.get(i).getMgdlxfs())+"',");
				sb.append("MGD_JD:'"+(list.get(i).getMgdjd()==null?"":list.get(i).getMgdjd())+"',");
				sb.append("MGD_WD:'"+(list.get(i).getMgdwd()==null?"":list.get(i).getMgdwd())+"',");
				sb.append("MGD_BZ:'"+(list.get(i).getMgdbz()==null?"":list.get(i).getMgdbz())+"'");
				sb.append("}");
				if(i<list.size()-1){
					sb.append(",");
				}
			}
		}
		sb.append("]}");
		getHttpServletResponse().getWriter().println(sb);
	}

}
